package 剑指offer;

import java.util.ArrayList;
import java.util.List;

public class _57和为s的连续正数序列 {
    public int[][] findContinuousSequence(int target) {
        List<int[]> vec = new ArrayList<>();
        int low = 1;
        int high = 2;

        while (low < high){
            // 等差数列求和
            int total = (low + high) * (high - low +1) / 2;
            if(target == total){
                int[] temp = new int[high-low+1];
                int index = 0;
                for (int i = low; i <= high; i++) {
                    temp[index++] = i;
                }
                vec.add(temp);
                low++;
            }else if(total < target){
                high++;
            }else {
                low++;
            }
        }
        return vec.toArray(new int[vec.size()][]);
    }
}
